import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:wk_robot2/app/const/AppConst.dart';
import 'package:wk_robot2/app/event/DataCallBack.dart';
import 'package:wk_robot2/app/event/MsgContentEvent.dart';
import 'package:wk_robot2/app/robot_comm/robot_status_listner.dart';
import 'package:wk_robot2/app/storage/StorageManager.dart';
import 'package:wk_robot2/app/utils/CommonUtil.dart';
import '../../../event/WkEventListener.dart';
import '../../../logger/Logger.dart';
import '../../../robot_comm/mqtt_comm_manager.dart';
import '../../../routes/app_pages.dart';
import '../../../widget/CommonWidgets.dart';
import 'package:wk_robot2/app/modules/growth/controllers/growth_controller.dart';
import '../../componentview/controllers/IndexViewController.dart';
import '../../componentview/controllers/MineViewController.dart';
import 'package:wk_robot2/app/modules/growth/views/growth_view.dart';
import '../../componentview/views/index_view_view.dart';
import '../../componentview/views/mine_view.dart';

class HomeController extends GetxController {

  var currentTabIndex = 0.obs;

  List<Widget> pages = [IndexViewView(),GrowthView(),MineView()];

  @override
  void onInit() {
    super.onInit();
    Get.put(IndexViewController(),permanent: true);
    Get.put(GrowthController(),permanent: true);
    Get.put(MineViewController(),permanent: true);

    //eventBus
  }

  @override
  void onReady() {
    super.onReady();
    eventBus.on<ProductContentEvent>().listen((event) {
      if(event.code == ACCOUNT_TOKEN_UNVAILABLE) {
        CommonWidgets.showSingleBtnDialog(Get.context!, '安全提醒', '账号已在其他设备登录,请重新登录', WkEventListener(
                      onClick: (v) {
                        print('点击了吗？ 222');
                        CommonUtil.clearCache(DataCallBack(businessCallBack: (v) {}));
                        Get.offAllNamed(Routes.LOGIN);
                      }
                  ));
      }
    });
  }

  @override
  void onClose() {
    super.onClose();
  }


  Widget getPageItem (int tabIndex) {
    return pages[tabIndex];
  }

  void onTap(int tabIndex) {
    currentTabIndex.value = tabIndex;

  }
  
}

